package com.tabjin.rfidsocket.common;

import com.tabjin.rfidsocket.pojo.SysUser;
import com.tabjin.rfidsocket.pojo.vo.SysUserVO;

import javax.servlet.http.HttpServletRequest;

/**
 * @author tabjin
 * create at 2020/12/21 22:27
 * @program rfid_socket
 * @description
 */
public class RequestHolder {
    private static final ThreadLocal<SysUserVO> userHolder = new ThreadLocal<SysUserVO>();

    private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<HttpServletRequest>();

    public static void add(SysUserVO sysUserVO) {
        userHolder.set(sysUserVO);
    }

    public static void add(HttpServletRequest request) {
        requestHolder.set(request);
    }

    public static SysUserVO getCurrentUser() {
        return userHolder.get();
    }

    public static HttpServletRequest getCurrentRequest() {
        return requestHolder.get();
    }

    /**
     * 移除操作，每个进程结束之后remove
     */
    public static void remove() {
        userHolder.remove();
        requestHolder.remove();
    }
}
